# !/usr/bin/env python
# encoding: utf-8
'''
  @author: HJW
  @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited.
  @contact: hejunwang01@126.com
  @file: yanzhengma.py
  @time: 2022/8/28 0028 上午 11:36
  @desc:
  '''
# 导入云打码
from  yundama import YdmVerify

import requests
from lxml import etree
url ="https://so.gushiwen.cn/user/login.aspx"
headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
    }

# 获取请求的内容
page_next = requests.get(url=url,headers=headers).text
#解析文件的
parse= etree.HTML(page_next)

imgpath = "https://so.gushiwen.cn"+parse.xpath('//*[@id="imgCode"]/@src')[0]
print(imgpath)

# 获取到图片
img_data = requests.get(imgpath,headers=headers).content
# 保存图片到本地
with open('./img.png','wb') as f:
    f.write(img_data)

# 调用打码进行识别
y = YdmVerify()
with open('./img.png','rb') as fp:
    img_content = fp.read()
ret= y.common_verify(img_content)
print(ret)

